package com.suray.wcs.res.enums;

import com.alibaba.fastjson.serializer.JSONSerializable;
import com.alibaba.fastjson.serializer.JSONSerializer;

import java.io.IOException;
import java.lang.reflect.Type;

public enum PalletStatus implements JSONSerializable {
    /**
     * 降下
     */
    DOWN(0, "下降"),
    /**
     * 顶升
     */
    UP(1, "顶升"),
    /**
     * 异常
     */
    ERROR(2, "异常"),
    /**
     * 未知
     */
    UNKNOWN(-1, "未知");
    /**
     * 对应数字
     */
    private int statusNum;
    private String description;

    PalletStatus(int statusNum, String description) {
        this.statusNum = statusNum;
        this.description = description;
    }

    public static PalletStatus parseStatus(int statusNum) {
        for (PalletStatus r : PalletStatus.values()) {
            if (r.getStatusNum() == statusNum) {
                return r;
            }
        }
        throw new IllegalArgumentException("匹配托盘状态参数异常");
    }

    public int getStatusNum() {
        return statusNum;
    }

    public String getDescription() {
        return description;
    }

    @Override
    public String toString() {
        return description;
    }

    @Override
    public void write(JSONSerializer jsonSerializer, Object arg1, Type arg2, int arg3) throws IOException {
        jsonSerializer.write(this.getDescription());
    }
}
